package com.twu.biblioteca.view;

import java.io.PrintStream;
import java.util.List;

import static com.google.common.collect.FluentIterable.from;


public class MessageView {

    public final static String WELCOME_MESSAGE = "Welcome to biblioteca";
    public final static String EXIT = "0.Exit" ;
    public final static String MAIN_MENU_COMMAND = "1.Main menu";
    public final static String SHOW_ALL_BOOKS = "2.List all Books";
    public final static String SHOW_AVAILABLE_BOOKS = "3.List available books";
    public final static String LOGIN = "4.Login";
    public final static String CHECK_OUT_BOOK = "5.Check out Book";
    public final static String RETURN_BOOK = "6.Return Book";
    public final static String SHOW_AVAILABLE_MOVIES = "7.List all available movies";
    public final static String CHECK_OUT_MOVIE = "8.Check out movie";
    public final static String SHOW_PERSONAL_INFORMATION = "9.Show personal information";
    public final static String INVALID_MENU_OPTION = "Select a valid option!";
    public final static String USER_ID = "please enter your ID: ";
    public final static String PASSWORD = "please enter your password: ";
    public final static String INVALID_USER = "user not exist: ";
    public final static String BOOK_NAME = "please enter book name: ";
    public final static String INVALID_BOOK_NAME = "That book is not available.";
    public final static String CHECK_OUT_SUCCESS = "Thank you! Enjoy the book!";
    public static final String RETURN_BOOK_SUCCESS = "Thank you for returning the book.";
    public static final String INVALID_RETURN_BOOK = "That is not a valid book to return";
    public static final String EXIT_MESSAGE = "Welcome come again";
    public static final String OPERATION_MESSAGE = "please enter a menu option";
    public static final String ENTER_MOVIE_NAME = "please enter movie name";
    public static final String CHECK_OUT_MOVIE_SUCCESS = "Thank you! Enjoy the movie!";
    public static final String INVALID_MOVIE_NAME = "That movie is not available";
    public static final String HAVE_NOT_LOGIN = "Must Login First!";

    private static final String[] MAIN_MENU_MESSAGES = new String[]{EXIT, MAIN_MENU_COMMAND, SHOW_ALL_BOOKS,
            SHOW_AVAILABLE_BOOKS, LOGIN, CHECK_OUT_BOOK, RETURN_BOOK, SHOW_AVAILABLE_MOVIES, CHECK_OUT_MOVIE,
            SHOW_PERSONAL_INFORMATION};

    private final PrintStream printer;

    public MessageView(PrintStream printer) {
        this.printer = printer;
    }

    public void showWelcomeMessage() {
        showMessagesInOrder(WELCOME_MESSAGE);
    }

    public void showMainMenu() {
        showMessagesInOrder(MAIN_MENU_MESSAGES);
    }

    public void showMessage(String message) {
        showMessagesInOrder(message);
    }

    private void showMessagesInOrder(String... messages) {
        for (String message : messages) {
            printer.println(message);
        }
    }

    public void showMessageList(List<String> information) {
        showMessagesInOrder(from(information).toArray(String.class));
    }

}
